using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.PatientDomain;
using ShivamEMR.Model.DataInterfaces.PatientDataInterf;
using ShivamEMR.Model;
//using ShivamEMR.Web.Areas.Patient.Models;

namespace ShivamEMR.Web.Areas.Patient.Controllers
{   
    public class DiagnosisController : Controller
    {
		private readonly IPatientRepository patientRepository;
		private readonly IDiagnosisStatusRepository diagnosisstatusRepository;
		private readonly IAdmissionRepository admissionRepository;
        private readonly IDiagnosticItemRepository diagnosticsitemRepository;
		private readonly IDiagnosisRepository diagnosisRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public DiagnosisController()
        {
            patientRepository = Registry.RepositoryFactory.GetPatientRepository();
            diagnosisstatusRepository = Registry.RepositoryFactory.GetDiagnosisStatusRepository();
            admissionRepository = Registry.RepositoryFactory.GetAdmissionRepository();
            diagnosticsitemRepository = Registry.RepositoryFactory.GetDiagnosticItemRepository();
            diagnosisRepository = Registry.RepositoryFactory.GetDiagnosisRepository();
        }

        public DiagnosisController(IPatientRepository patientRepository, IDiagnosisStatusRepository diagnosisstatusRepository, IAdmissionRepository admissionRepository, IDiagnosticItemRepository diagnosticsitemRepository, IDiagnosisRepository diagnosisRepository)
        {
			this.patientRepository = patientRepository;
			this.diagnosisstatusRepository = diagnosisstatusRepository;
			this.admissionRepository = admissionRepository;
			this.diagnosticsitemRepository = diagnosticsitemRepository;
			this.diagnosisRepository = diagnosisRepository;
        }

        //
        // GET: /Diagnosis/

        public ViewResult Index()
        {
     //       return View(diagnosisRepository.AllIncluding(diagnosis => diagnosis.Patient, diagnosis => diagnosis.DiagnosisStatus, diagnosis => diagnosis.Admission, diagnosis => diagnosis.Diseases));
            return View(diagnosisRepository.All);
        }

        //
        // GET: /Diagnosis/Details/5

        public ViewResult Details(System.Guid id)
        {
            return View(diagnosisRepository.Find(id));
        }

        //
        // GET: /Diagnosis/Create

        public ActionResult Create()
        {
			ViewBag.PossiblePatients = patientRepository.All;
			ViewBag.PossibleDiagnosisStatus = diagnosisstatusRepository.All;
			ViewBag.PossibleAdmissions = admissionRepository.All;
			ViewBag.PossibleDiagnosticsItems = diagnosticsitemRepository.All;
            return View();
        } 

        //
        // POST: /Diagnosis/Create

        [HttpPost]
        public ActionResult Create(Diagnosis diagnosis)
        {
            if (ModelState.IsValid) {
                diagnosisRepository.InsertOrUpdate(diagnosis);
                diagnosisRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossiblePatients = patientRepository.All;
				ViewBag.PossibleDiagnosisStatus = diagnosisstatusRepository.All;
				ViewBag.PossibleAdmissions = admissionRepository.All;
				ViewBag.PossibleDiagnosticsItems = diagnosticsitemRepository.All;
				return View();
			}
        }
        
        //
        // GET: /Diagnosis/Edit/5
 
        public ActionResult Edit(System.Guid id)
        {
			ViewBag.PossiblePatients = patientRepository.All;
			ViewBag.PossibleDiagnosisStatus = diagnosisstatusRepository.All;
			ViewBag.PossibleAdmissions = admissionRepository.All;
			ViewBag.PossibleDiagnosticsItems = diagnosticsitemRepository.All;
             return View(diagnosisRepository.Find(id));
        }

        //
        // POST: /Diagnosis/Edit/5

        [HttpPost]
        public ActionResult Edit(Diagnosis diagnosis)
        {
            if (ModelState.IsValid) {
                diagnosisRepository.InsertOrUpdate(diagnosis);
                diagnosisRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossiblePatients = patientRepository.All;
				ViewBag.PossibleDiagnosisStatus = diagnosisstatusRepository.All;
				ViewBag.PossibleAdmissions = admissionRepository.All;
				ViewBag.PossibleDiagnosticsItems = diagnosticsitemRepository.All;
				return View();
			}
        }

        //
        // GET: /Diagnosis/Delete/5
 
        public ActionResult Delete(System.Guid id)
        {
            return View(diagnosisRepository.Find(id));
        }

        //
        // POST: /Diagnosis/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(System.Guid id)
        {
            var diagno = diagnosisRepository.Find(id);
            diagnosisRepository.Delete(diagno);
            diagnosisRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

